package cn.gz.zoomtech.common;

import java.io.File;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

//import org.apache.log4j.Logger;


public class Tools {
//    private static final Logger log = Logger.getLogger(Tools.class);

	/**
	 * 
	* 功能描述: MD5加密字符串
	* @param str
	* @return md5Str
	* @author chenhui / 2010-1-5 下午01:32:01
	 */
	public static String getMD5String(String str,String key)
    {
        try{   
        	Calendar oneCalendar=Calendar.getInstance();
			SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
			String suffix=df.format(oneCalendar.getTime());
			
			str = str+suffix+key;
            byte[] res=str.getBytes();
            MessageDigest md = MessageDigest.getInstance("MD5".toUpperCase());
            byte[] result=md.digest(res);
            for(int i=0;i<result.length;i++)
            {
                md.update(result[i]);
            }
            byte[] hash=md.digest();
            StringBuffer d=new StringBuffer("");
            for(int i=0;i<hash.length;i++)
            {
                int v=hash[i] & 0xFF;
                if(v<16) d.append("0");
                    d.append(Integer.toString(v,16).toUpperCase()+"");
            }
                return d.toString();
        }
        catch(Exception e)
        {
            return "";
        }
    }
	/**
	 * 
	* 功能描述: 获取当前月的实际天数
	* @return value 
	* @author chenhui / 2010-1-8 下午04:03:41
	 */
	public static int getCurrentMonthDays(){
		int value = 28;
		try{
		    Calendar cal = Calendar.getInstance();
		    value = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		}catch(Exception ex){
		    System.out.println("getNextMonthDays Error:"+ex);	
		}
		
		return value;
	}
	
	public static String getDateStr(Date date){
		String dateStr="";
		try{
		    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		    dateStr = df.format(date);
		}catch(Exception ex){
			System.out.println("getDateStr Error:"+ex);
		}
		return dateStr;
	}

	/**
	 * 小工具
	* 功能描述: 生成bat 或者shell脚本中需要的Lib jar 路径字符串
	* @param path
	* @author chenhui / 2010-1-26 上午11:22:25
	 */
public static void getFileNames(String path){
		
		File file = new File(path);
		String[] files = file.list(); 
		String filename;
		StringBuffer libline = new StringBuffer();
//		set ClassPath=.;conf/;lib/classes12.jar;lib/commons-collections-2.1.1.jar;lib/commons-dbcp-1.2.1.jar;lib/commons-lang-2.1.jar;lib/commons-logging.jar;lib/commons-net-1.4.0.jar;lib/commons-pool.jar;lib/ejb.jar;lib/j2ee.jar;lib/jdoclient.jar;lib/jms.jar;lib/jftp-bin-0_70.jar;lib/jmx.jar;lib/jndi.jar;lib/jta.jar;lib/log4j-1.2.8.jar;lib/oc4jclient.jar;lib/ojdbc14.jar;lib/servlet-api.jar;lib/xmlparserv2.jar;lib/xstream-1.1.2.jar;lib/jftp-bin-0_70.jar;lib/commons-lang-2.1.jar;

        if(files!=null){
        	libline.append("set ClassPath=.;conf/;lib/");  // bat模式
//        	libline.append("set ClassPath=.:./conf/:./lib/"); // sh模式
        	for(int i =0;i<files.length;i++){
        		filename = files[i];
//        		libline.append(filename+":./lib/");
        		libline.append(filename+";lib/");
        		
        	}
        	System.out.println("libline:"+libline);
        }
	}





	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		Tools t = new Tools(); // D:\work2009\wapUserCacheClient\lib
		String path = "D:\\workspace-zoom\\project-java\\phonePosinfo\\depoly\\lib\\";
//		Tools.getFileNames(path);
//		int a = 12345678;
//		byte[] r = FormatTransfer.toLH(a);
//		int b = FormatTransfer.lBytesToInt(r);
//		System.out.println("a:"+a+",b:"+b);
		
		String str_dis = "0.6026211132298391";
		double d_dis = Double.valueOf(str_dis)/1.5;
		System.out.println("str_dis:"+str_dis+",d_dis:"+d_dis);
		
		
		 DecimalFormat   myDecformat=new   java.text.DecimalFormat("#0.00000");   
 
		  double a= 123.763096918092992;   
//		  a= 3.1416;    
		    
		  System.out.println(myDecformat.format(a));
		
		
	}
	
}
